import { Component } from 'react'
import { Route } from 'react-router-dom'
import loadable from '@loadable/component'
import { inject, observer } from "mobx-react";
import Home from '../pages/Home'
import Index from "./content";
// import Home from "../pages/Home";
import CashOut from "../pages/hanqun/CashOut";
import AccountManage from "../pages/hanqun/AccountManage";
import UserManagement from "../pages/UserManagement";
@inject('login')
@observer
class Droute extends Component {
    constructor() {
        super();
        this.state = {
            routelist: []
        }
    }
    bindRouter(list) {
        // console.log('list',list)
        let arr = []
        let routerlist = list.map((item) => {
            if (item.childrens && item.childrens.length > 0) {

                arr.push(<Route path={item.menuUrl} key={item.menuId} component={loadable(() => {
                    return import('./' + item.componentPath)
                })
                }>
                </Route>)
                arr.push(...this.bindRouter(item.childrens));
            } else {
                arr.push(
                    <Route path={item.menuUrl} key={item.menuId} component={loadable(() => {
                        return import('../pages/' + item.componentPath)
                    })
                    }>
                    </Route>
                )
            }
        })
        return arr;
    }
    componentDidMount() {
        // console.log(this.props.login.gongnengInfo);
        let routelist = this.bindRouter(JSON.parse(sessionStorage.getItem('gongnengInfo')));
        this.setState({
            routelist: routelist
        }, () => {
            console.log('routelist', this.state.routelist)
        })
    }

    render() {
        return (
            <>
                {this.state.routelist}
            </>
        )
    }
}
export default Droute